#include "stdio.h"
#include "stdlib.h"

#define Null 0

struct student{
    int data;
    struct student *next;
};

struct student * reat_chain_table(int n);
void input(struct student *x);
void outout(struct student *y);
void insert(struct student *z,struct student *pi);
int delete(struct student *t,int num);

int main()
{
    int num;
    struct student aim;
    struct student *p=&aim,*head;
    scanf("%d",&num);
    head=reat_chain_table(num);
    input(head);
    scanf("%d",&(p->data));
    insert(head, p);
    delete(head, 5);
    outout(head);
    return 0;
}

struct student * reat_chain_table(int n)
{
    struct student *head = NULL,*pf = NULL,*pd;
    for (int i=0; i<n; i++) {
        pd=(struct student *)malloc(sizeof(struct student));
        if (i==0) {
            pf=head=pd;
        }
        else{
            pf->next=pd;
        }
        pd->next=Null;
        pf=pd;
    }
    return head;
}

void input(struct student *x)
{
    while (x!=Null) {
        scanf("%d",&(x->data));
        x=x->next;
    }
}

void outout(struct student *y)
{
    while (y!=Null) {
        printf("%d",y->data);
        y=y->next;
    }
}

void insert(struct student *z,struct student *pi)
{
    struct student *pf = NULL,*pd;
    pd=z;
    if (z==Null) {
        z=pi;
        pi->next=Null;
    }
    else{
        while ((pi->data>pd->data)&&(pd->next!=Null)) {
            pf=pd;
            pd=pd->next;
        }
        if (pi->data<pd->data) {
            if (z==pd) {
                z=pi;
            }
            else{
                pf->next=pi;
            }
            pi->next=pd;
        }
        else{
            pd->next=pi;
            pi->next=Null;
        }
    }
}

int delete(struct student *t,int num)
{
    struct student *pf = NULL,*pb;
    if (t==Null) {
        return 0;
    }
    pb=t;
    while (pb->data!=num&&pb->next!=Null) {
        pf=pb;
        pb=pb->next;
    }
    if (pb->data==num) {
        if(pb==t){
            t=pb->next;
        }
        else{
            pf->next=pb->next;
        }
        free(pb);
    }
    return 0;
}